define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'applymanager/business/index' + location.search,
                    add_url: 'applymanager/business/add',
                    edit_url: 'applymanager/business/edit',
                    del_url: 'applymanager/business/del',
                    multi_url: 'applymanager/business/multi',
                    table: 'self_join_business',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [{
                            checkbox: true
                        },
                        {
                            field: 'id',
                            title: __('Id'),
                            searchable: false
                        },
                        {
                            field: 'user_id',
                            title: __('User_id'),
                            searchable: false,
                            formatter: function(v,r,i){
                                return r.user_info.nickname
                            }
                        },
                        {
                            field: 'join_no',
                            title: __('Join_no')
                        },
                        {
                            field: 'join_name',
                            title: __('Join_name')
                        },
                        {
                            field: 'real_name',
                            title: __('Real_name')
                        },
                        {
                            field: 'mobile',
                            title: __('Mobile')
                        },
                        {
                            field: 'company',
                            title: __('Company')
                        },
                        {
                            field: 'business_time',
                            title: __('Business_time'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'bussiness_amount',
                            title: __('Bussiness_amount'),
                            operate: 'BETWEEN'
                        },
                        {
                            field: 'bussiness_title',
                            title: __('Bussiness_title')
                        },
                        {
                            field: 'pay_type',
                            title: __('Pay_type'),
                            searchList: {
                                "0": __('Pay_type 0'),
                                "1": __('Pay_type 1')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'pay_way',
                            title: __('Pay_way'),
                            searchList: {
                                "0": __('Pay_way 0'),
                                "1": __('Pay_way 1')
                            },
                            formatter: Table.api.formatter.normal
                        },
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        // {
                        //     field: 'operate',
                        //     title: __('Operate'),
                        //     table: table,
                        //     events: Table.api.events.operate,
                        //     formatter: Table.api.formatter.operate
                        // }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});